package com.fenqing.leetcode.code.t2300_2400;

import com.fenqing.annotations.Execute;
import com.fenqing.core.Topic;

public class Topic2391 extends Topic {

    @Execute
    public int garbageCollection(String[] garbage, int[] travel) {
        int a = 0, b = 0, c = 0;
        int result = 0;
        for (int i = 0; i < garbage.length; i++) {
            String garbage1 = garbage[i];
            for (int j = 0; j < garbage1.length(); j++) {
                char ch = garbage1.charAt(j);
                if (a < i && ch == 'M') {
                    a = i;
                }
                if (b < i && ch == 'P') {
                    b = i;
                }
                if (c < i && ch == 'G') {
                    c = i;
                }
            }
            result += garbage1.length();
        }
        for (int i = 0, j = 1; j < travel.length; i++, j++) {
            travel[j] = travel[j] + travel[i];
        }
        result += a < 1 ? 0 : travel[a - 1];
        result += b < 1 ? 0 : travel[b - 1];
        result += c < 1 ? 0 : travel[c - 1];
        return result;
    }

    public static void main(String[] args) {
        Topic2391 topic2391 = new Topic2391();
        int run = topic2391.run("[\"MMM\",\"PGM\",\"GP\"]", "[3,10]");
        System.out.println(run);
    }

}
